package com.liushao.config;


import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.reactive.CorsWebFilter;
import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource;

/**
 * @author 陈修华
 * @ClassName CorsConfigs
 * @description: TODO
 * @datetime 2025年 01月 07日 14:34
 * @version: 1.0
 */
@Configuration
public class CorsConfigs {

    @Bean
    public CorsWebFilter corsWebFilter(){//解决跨域  跨域的代码多种写法  解决vue
        CorsConfiguration config=new CorsConfiguration();
        config.addAllowedMethod("*");
        config.addAllowedOrigin("*");
        config.addAllowedHeader("*");
        config.setAllowCredentials(true);
        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
        source.registerCorsConfiguration("/**",config);
        return new CorsWebFilter(source);
    }
}
